package org.example.springboot.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.v3.oas.annotations.Operation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.example.springboot.common.annotation.Loggable;
import org.example.springboot.common.annotation.RateLimit;
import org.example.springboot.common.utils.Result;
import org.example.springboot.convert.DecisionTimeConvert;
import org.example.springboot.entity.DecisionTime;
import org.example.springboot.service.DecisionTimeService;
import org.example.springboot.vo.DecisionTimeVO;
import org.springframework.web.bind.annotation.*;

/**
 * 灌溉日志
 *
 * @author Fz
 * @since 1.0.0 2024-08-02
 */
@Slf4j
@RestController
@RequestMapping("/decision-time")
@AllArgsConstructor
public class DecisionTimeController {

    private final DecisionTimeService decisionTimeService;

    @PostMapping("/decisionTimeSet")
    @Operation(summary = "保存决策时间")
    @Loggable(description = "决策时间设置")
    @RateLimit(max = 1, timeout = 10)
    public Result<String> decisionTimeSet(@RequestBody DecisionTime decisionTime) {
        decisionTimeService.decisionTimeSet(decisionTime);
        return Result.ok();
    }

    @GetMapping("/getDecisionTimeId")
    @Operation(summary = "信息")
    public Result<DecisionTimeVO> getDecisionTimeId() {
        DecisionTime decisionTime = decisionTimeService.getOne(new QueryWrapper<>());
        return Result.ok(DecisionTimeConvert.INSTANCE.convert(decisionTime));
    }

}